package servlet.events;

import java.util.HashMap;
import java.util.Map;

import servlet.Constants;
import util.Debug;

public class EventHandlerFactory {
	Map<String, EventHandler> handlers = new HashMap<String, EventHandler>();
	
	public EventHandlerFactory(Map<String, EventHandler> handlers) {
		this.handlers = handlers;
	}
	
	public EventHandler getHandler(String event) {
		EventHandler handler;
		try {
			handler = (EventHandler) handlers.get(event);
		} catch (Exception exc) {
			handler = (EventHandler) handlers.get(Constants.UNKNOWN_EVENT);
		}
		Debug.log (this, "getEventHandler", "handler=" + handler.getClass().getName());
		return handler;
	}
}
